package gameManager;

import java.awt.Dimension;
import java.awt.Image;
import java.awt.Point;
import java.util.ArrayList;
import java.util.List;
import javax.swing.ImageIcon;

public abstract class GameCharacter implements Interactable{
    private String myName;
    private Point myPosition;
    private int myDirection;
    private int mySpeed;
    private Image myImage;
    private int myHealth;
    private List<WeaponObject> myWeapons = new ArrayList<WeaponObject> ();
    private List<String> NamesOfObjectsCanCollideWith = new ArrayList<String> ();
    private Dimension mySize;
    
    
    public void update(int trigger){
        move();
        updateWeapons(trigger);
        //System.out.print(getHealthValue());
    }
    
    public void move() {
        int dx = (int) Math.round(Math.cos(getDirection() * Math.PI / 180 )*getSpeed());
        int dy = (int) Math.round(Math.sin(getDirection() * Math.PI / 180 )*getSpeed());
        
        getInteractablePosition().translate(dx, dy);
    }
    
    public int getSpeed(){
        return mySpeed;
    }
   
    public void setSpeed (int speed) {
        mySpeed = speed;
    }
    
    public Point getInteractablePosition() {
        return myPosition;
    }
    
    public void setInteractablePosition(Point newPosition) {
        myPosition = newPosition;
    }
    
    public String getNameOfInteractable(){
        return myName;
    }
    
    public void setNameOfInteractable(String newName) {
        myName = newName;
    }
    
    
    public void addCollisionObject(String newCollisionObject){
        if (!NamesOfObjectsCanCollideWith.contains(newCollisionObject)) {
            NamesOfObjectsCanCollideWith.add(newCollisionObject);
        }
    }
    
    public void setDirection(int newDirection){
        myDirection = newDirection;
    }
    
    public void updateDirection(int dDirection){
        myDirection += dDirection;
    }
    
    public int getDirection(){
        return myDirection;
    }
    
    public void setHealthValue(int newHealthValue) {
        myHealth = newHealthValue;
    }
    
    public int getHealthValue(){
        return myHealth;
    }
      
    public void changeHealthValue (int dHealthValue){
        myHealth += dHealthValue;
    }
    
    public void setObjectImage(String imageFilePath) {
        ImageIcon objectIcon = new ImageIcon(imageFilePath);
        myImage = objectIcon.getImage();
    }

    public Image getObjectImage(){
        return myImage;
    }
    
    public void addNewWeapon (WeaponObject newWeapon) {
        myWeapons.add(newWeapon);
    }

    public List<WeaponObject> getMyWeapons(){
        return myWeapons;
    }

    public void updateWeapons (int trigger){
        for (WeaponObject weapon : myWeapons) {
            weapon.updateCoolDownWaitingTime(trigger);
        }
    }
    
    public void removeCollisionObject(String oldCollisionObject) {
        if (NamesOfObjectsCanCollideWith.contains(oldCollisionObject)) {
            NamesOfObjectsCanCollideWith.remove(oldCollisionObject);
        }
    }
    
    public List<Interactable> fire() {
        List<Interactable> newShots = new ArrayList<Interactable>();
        for (WeaponObject weap : getMyWeapons()) {
            newShots.addAll(weap.fire());
        }
        return newShots;
    }
    
    public Dimension getDimension() {
        return mySize;
    }
    
    public void setDimension(Dimension newSize) {
        mySize = newSize;
    }  

    public Point getCenter () {
        return new Point(myPosition.x + Math.round(mySize.width/2), myPosition.y + Math.round(mySize.height/2));
    }
    
    public ArrayList<String> getNamesOfInteractableCanCollideWith () {
        return (ArrayList<String>) NamesOfObjectsCanCollideWith;
    }
    
    public void setNamesOfInteractableCanCollideWith(List<String> names) {
        NamesOfObjectsCanCollideWith = names;
    }
}
